package com.imooc.ecommerce.contoller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.imooc.ecommerce.common.TableId;
import com.imooc.ecommerce.goods.DeductGoodsInventory;
import com.imooc.ecommerce.goods.GoodsInfo;
import com.imooc.ecommerce.goods.SimpleGoodsInfo;
import com.imooc.ecommerce.service.IGoodsService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 商品微服务对外暴露的功能服务api接口
 * @Author: zhangshao
 * @Since: 2023/12/4 18:22
 */
@Slf4j
@RestController
@RequestMapping("/goods")
public class GoodsController {

	@Autowired
	private IGoodsService goodsService;

	@ApiOperation(value = "详细商品信息", notes = "根据TableId查询商品信息", httpMethod = "POST")
	@PostMapping("/goods-info")
	public List<GoodsInfo> getGoodsInfoByTableId(@RequestBody TableId tableId) {
		return goodsService.getGoodsInfoByTableId(tableId);
	}

	@ApiOperation(value = "简单商品信息", notes = "获取分页的简单商品信息", httpMethod = "GET")
	@GetMapping("/page-simple-goods-info")
	public IPage<SimpleGoodsInfo> getSimpleGoodsInfoByPage(
			@RequestParam(required = false, defaultValue = "1") int page) {
		return goodsService.getSimpleGoodsInfoByPage(page);

	}

	@ApiOperation(value = "简单商品信息", notes = "根据TableId查询简单商品信息")
	@PostMapping("/simple-goods-info")
	public List<SimpleGoodsInfo> getSimpleGoodsInfoByTableId(@RequestBody TableId tableId) {
		return goodsService.getSimpleGoodsInfoByTableId(tableId);
	}

	@ApiOperation(value = "扣减商品库存",notes = "扣减商品库存",httpMethod = "POST")
	@PostMapping("/deduct-goods-inventory")
	public Boolean deductGoodsInventory(@RequestBody List<DeductGoodsInventory> deductGoodsInventories) {
		return goodsService.deductGoodsInventory(deductGoodsInventories);
	}

}
